import axios from "axios"
const nineModule ={
    state:{
        TravelInfo:[],
        Traveltitle:[],
        tickets:[],
        ticketsDetail:{}
    },
    mutations:{
        setTravelInfo:function(state,value){
            state.TravelInfo=[]
            for(var i = 0;i<value.length;i++){
                state.Traveltitle.push(value[i].countryName)
                for(var j=0;j<value[i].list.length;j++){
                    state.TravelInfo =state.TravelInfo.concat(value[i].list[j]);
                }
            }
            // console.dir(state.Traveltitle)
             
        },
        // 清空数组
        resetArr:function(state){
            state.Traveltitle=[]
        },
        // 所有门票信息
        setTickets(state,value){
            state.tickets=value
        },
        // 单个门票详情
        setTicketsDetail(state,value){
            // console.log(value)
            state.ticketsDetail = value
        }
       
    },
    actions:{
        requestTravel(state){
            //  state.Traveltitle=[]
            axios.get("/api/travel")
            .then(res=>{
                // console.dir(res.data.msg)
                state.commit("setTravelInfo",res.data.msg)
            })
        },
        requestTicket(state){
            axios.get("/api/ticket")
            .then(res=>{
                // console.log(res.data.msg[0])
                state.commit("setTickets",res.data.msg[0].list)
            })
        },
        // 门票的详细信息
        requestEachTicket(state,n){
            // console.log(n)
            axios.post("/api/ticketsDetail",{n})
            .then(res=>{
                // console.log(res.data.msg);
                state.commit("setTicketsDetail",res.data.msg)
            })
        }
        
    }
}

export default nineModule;